package com.weishu.finace.job;


import com.github.pagehelper.PageInfo;
import com.weishu.core.entity.CwCheckBatch;
import com.weishu.core.entity.CwPayOrder;
import com.weishu.core.service.ICwPayOrderService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

@Component
@Slf4j
public class XxlJobPayOrder {

    @Autowired
    private ICwPayOrderService iCwPayOrderService;

    @XxlJob("finaceUserHandler")
    public void jobTestHandler() {
        //获取今天日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String nowDate = sdf.format(new Date());

        //获取前一天日期
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(new Date());
        calendar.add(calendar.DATE,-1);
        String pastDate = sdf.format(calendar.getTime());

        CwPayOrder cwPayOrder = new CwPayOrder();
        cwPayOrder.setSrarttradeDateFq(calendar.getTime());
        cwPayOrder.setEndtradeDateFq(new Date());
        //查询交易流水信息
        List<CwPayOrder> payOrderList = iCwPayOrderService.getList(cwPayOrder);
        //创建对账批次表对象
        CwCheckBatch cwCheckBatch = new CwCheckBatch();
        //同一天内对账批次序号
        int count = 1;
        //循环添加对账批次表信息
        for (CwPayOrder payOrder : payOrderList) {
            cwCheckBatch.setBatchNo(nowDate);
            cwCheckBatch.setBatchNum(count);
            cwCheckBatch.setBillDay(nowDate);
            count++;
        }

    }
}
